def is_prime(n):
    if n <= 1:
        return False
    if n <= 3:
        return True
    if n % 2 == 0 or n % 3 == 0:
        return False
    i = 5
    while i * i <= n:
        if n % i == 0 or n % (i + 2) == 0:
            return False
        i += 6
    return True

def word_to_number(word):
    numbers = {
        "zero": 0, "one": 1, "two": 2, "three": 3, "four": 4,
        "five": 5, "six": 6, "seven": 7, "eight": 8, "nine": 9
    }
    return numbers.get(word)

def nearest_prime(words):
    nums = [word_to_number(word) for word in words.split()]
    if None in nums or len(nums) != 3:
        print("Wrong input")
        return
    num = nums[0] * 100 + nums[1] * 10 + nums[2]
    lower_prime = num
    upper_prime = num
    while not is_prime(lower_prime) and not is_prime(upper_prime):
        lower_prime -= 1
        upper_prime += 1
    while not is_prime(lower_prime):
        lower_prime -= 1
    while not is_prime(upper_prime):
        upper_prime += 1
    if is_prime(lower_prime):
        print(lower_prime)
    else:
        print(upper_prime)

input_text = input("Введите три слова: ")
nearest_prime(input_text)
